package cn.xmy.demo01.servlet;


import cn.xmy.demo01.pojo.Shops;
import cn.xmy.demo01.service.ShopDaoService;
import cn.xmy.demo01.service.impl.ShopServiceDaoImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;


import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/findShopsServlet")
public class FindShopsServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ShopDaoService shopServiceDao=new ShopServiceDaoImpl();
        List<Shops>shops=null;
        try {
            shops=shopServiceDao.FindShops();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

        req.setAttribute("shops",shops);
        req.getRequestDispatcher("shops.html").forward(req,resp);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
